I mounted the motor on the CNC and it works pretty well.
However, I don't seem to be able to use the step response
screen. I have been tuning the loop by trial and error,
setting the parameters in the c code. However, setting a
motion in the step response screen causes the motor not to
move at all (small movements), or run away (large
movements) - kind of like when the servo gain is inverted.
However, the thing happens independent of servo gain sign
- and anyway, the loop works when everything is set in
code so the gain there is correct. I am probably
overflowing a variable somewhere or something.
Here the code that works well enough to let me jog the
axis in kmotionCNC:
#include "KMotionDef.h"
int main()
{
WriteSnapAmp(SNAP0+SNAP_PEAK_CUR_LIMIT0,9); //
current limit
WriteSnapAmp(SNAP0+SNAP_PEAK_CUR_LIMIT1,9); //
current limit
WriteSnapAmp(SNAP0+SNAP_SUPPLY_CLAMP0
,SNAP_CONVERT_VOLTS_TO_ADC(70.0));
WriteSnapAmp(SNAP0+SNAP_SUPPLY_CLAMP1
,SNAP_CONVERT_VOLTS_TO_ADC(70.0));
WriteSnapAmp(SNAP0+SNAP_SUPPLY_CLAMP_ENA0,1);
WriteSnapAmp(SNAP0+SNAP_SUPPLY_CLAMP_ENA1,1);
ch4->InputMode=ENCODER_MODE;
ch4->OutputMode=NO_OUTPUT_MODE;
ch4->Vel=10000;
ch4->Accel=1e+05;
ch4->Jerk=1e+07;
ch4->P=10.0;
ch4->I=0.001;
ch4->D=0;
ch4->FFAccel=0;
ch4->FFVel=0;
ch4->MaxI=200;
ch4->MaxErr=1e+06;
ch4->MaxOutput=400;
ch4->DeadBandGain=1;
ch4->DeadBandRange=0;
ch4->InputChan0=10;
ch4->InputChan1=9;
ch4->OutputChan0=8;
ch4->OutputChan1=9;
ch4->MasterAxis=-1;
ch4->LimitSwitchOptions=0x100;
ch4->LimitSwitchNegBit=0;
ch4->LimitSwitchPosBit=0;
ch4->SoftLimitPos=1e+09;
ch4->SoftLimitNeg=-1e+09;
ch4->InputGain0=-1;
ch4->InputGain1=1;
ch4->InputOffset0=0;
ch4->InputOffset1=0;
ch4->OutputGain=1;
ch4->OutputOffset=0;
ch4->SlaveGain=1;
ch4->BacklashMode=BACKLASH_OFF;
ch4->BacklashAmount=0;
ch4->BacklashRate=0;
ch4->invDistPerCycle=1;
ch4->Lead=0;
ch4->MaxFollowingError=200;
ch4->StepperAmplitude=35;
ch4->Position = 0;
ch4->Dest = 0;
ch4->iir[0].B0=1;
ch4->iir[0].B1=0;
ch4->iir[0].B2=0;
ch4->iir[0].A1=0;
ch4->iir[0].A2=0;
ch4->iir[1].B0=1;
ch4->iir[1].B1=0;
ch4->iir[1].B2=0;
ch4->iir[1].A1=0;
ch4->iir[1].A2=0;
ch4->iir[2].B0=1;
ch4->iir[2].B1=0;
ch4->iir[2].B2=0;
ch4->iir[2].A1=0;
ch4->iir[2].A2=0;
DefineCoordSystem(4,-1,-1,-1); //define ch4 as x
WritePWMR(8,0); // write PWM directly to channel 8,
with power +-400
while(1)
{
int output = (ch4->Output);
WaitNextTimeSlice();
if (0 == ch4->Enable)
WritePWMR(8,0); // write PWM directly to
channel 8, with power +-400
else
WritePWMR(8,output); // write PWM directly
to channel 8, with power +-400
}
}